package com.li.controller;

import com.li.model.ProjectReport;
import com.li.model.UserProject;
import com.li.service.ProjectReportService;
import io.swagger.annotations.*;
import org.apache.commons.collections4.Get;
import org.apache.shiro.util.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

@Api(tags = "用户工程报告管理")
@RestController
public class ProjectReportController {
    @Autowired
    private ProjectReportService projectReportService;


    @ApiOperation(value = "获取工程id下的所有报告", nickname = "queryAllProjectReport", notes = "获取工程id下的所有报告", response = ProjectReport.class, responseContainer = "List")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "success", response = ProjectReport.class, responseContainer = "List")
    })
    @GetMapping(value = "/com/pro_report/queryAll/{pid}", produces = { "application/json" })
    public ResponseEntity<List<ProjectReport>> queryAllProjectReport(@PathVariable("pid")long pid){
        List<ProjectReport> reports = projectReportService.queryAllReportByPid(pid);
        if (CollectionUtils.isEmpty(reports)){
            return ResponseEntity.ok(Collections.emptyList());
        }
        return ResponseEntity.ok(reports);
    }


    @ApiOperation(value = "根据报告id获取报告数据", nickname = "queryById", notes = "根据报告id获取报告数据", response = ProjectReport.class)
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "success", response = ProjectReport.class)
    })
    @GetMapping(value = "/com/pro_report/query/{id}", produces = { "application/json" })
    public ResponseEntity<ProjectReport> queryById(@PathVariable("id") long id){
        Optional<ProjectReport> reports = projectReportService.queryReportById(id);
            if (!reports.isPresent()){
                return ResponseEntity.notFound().build();
            }
            return ResponseEntity.ok(reports.get());
    }
    @ApiOperation(value = "根据id删除报告", nickname = "deleteById", notes = "根据id删除报告")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "success")
    })
    @GetMapping(value = "/com/pro_report/delete/{id}", produces = { "application/json" })
    public ResponseEntity<Void> deleteById(@PathVariable("id") long id){
        this.projectReportService.deleteReport(id);
        return ResponseEntity.ok().build();
    }

}
